home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Examples / Draw / Sources / DrawProxy.cpp < prev    next >
Encoding:
Text File  |  1994-04-21  |  9.4 KB  |  342 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                DrawProxy.cpp
  4. //    Release Version:    $ 1.0d1 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //    Creation Date:        3/28/94
  8. //
  9. //    Copyright:    © 1993, 1994 by Apple Computer, Inc., all rights reserved.
  10. //
  11. //========================================================================================
  12.  
  13. #ifndef DRAWPROXY_H
  14. #include "DrawProxy.h"
  15. #endif
  16.  
  17. #ifndef DRAWPART_H
  18. #include "DrawPart.h"
  19. #endif
  20.  
  21. #ifndef DRAWFRAME_H
  22. #include "DrawFrame.h"
  23. #endif
  24.  
  25. #ifndef SHAPES_H
  26. #include "Shapes.h"
  27. #endif
  28.  
  29. #ifndef DRAWPROXYBORDER_
  30. #include "DrawProxyBorder.h"
  31. #endif
  32.  
  33. // ----- Framework Includes -----
  34.  
  35. #ifndef FWUTIL_H
  36. #include "FWUtil.h"
  37. #endif
  38.  
  39. #ifndef FWPART_H
  40. #include "FWPart.h"
  41. #endif
  42.  
  43. #ifndef FWPARTING_H
  44. #include "FWParting.h"
  45. #endif
  46.  
  47. #ifndef FWFACET_H
  48. #include <FWFacet.h>
  49. #endif
  50.  
  51. #ifndef FWRECT_H
  52. #include "FWRect.h"
  53. #endif
  54.  
  55. // ----- OPF Foundation Includes -----
  56.  
  57. #ifndef BCOLL_H
  58. #include <BCColl.h>
  59. #endif
  60.  
  61. // ----- OpenDoc Includes -----
  62.  
  63. #ifndef _SHAPE_
  64. #include <Shape.h>
  65. #endif
  66.  
  67. #ifndef _TRNSFORM_
  68. #include <Trnsform.h>
  69. #endif
  70.  
  71. // ----- Macintosh Includes -----
  72.  
  73. #ifndef mathRoutinesIncludes
  74. #include <math routines.h>
  75. #endif
  76.  
  77. #pragma segment drawpart
  78.  
  79. //=========================================================================
  80. //    •• CDrawProxyRun
  81. //=========================================================================
  82.  
  83. //------------------------------------------------------------------------------
  84. //    • CDrawProxyRun::CDrawProxyRun
  85. //------------------------------------------------------------------------------
  86.  
  87. CDrawProxyRun::CDrawProxyRun()
  88. {
  89.     fShape = NULL;
  90. }
  91.  
  92. //------------------------------------------------------------------------------
  93. //    • CDrawProxyRun::InitDrawProxyRun
  94. //------------------------------------------------------------------------------
  95.  
  96. void CDrawProxyRun::InitDrawProxyRun(CDrawPart* drawPart)
  97. {
  98.     InitProxyRun(drawPart);
  99.     fDrawPart = drawPart;
  100. }
  101.  
  102. //------------------------------------------------------------------------------
  103. //    • CDrawProxyRun::~CDrawProxyRun
  104. //------------------------------------------------------------------------------
  105.  
  106. CDrawProxyRun::~CDrawProxyRun()
  107. {
  108. }
  109.  
  110. //------------------------------------------------------------------------------
  111. //    • CDrawProxyRun::GetFacetExternalTransform
  112. //------------------------------------------------------------------------------
  113.  
  114. void CDrawProxyRun::GetFacetExternalTransform(XMPFrame* xmpFrame, XMPTransform* facetTransform)
  115. {
  116. FW_UNUSED(xmpFrame);
  117.  
  118.     FW_CRect box = fShape->GetBoundingBox();
  119.     facetTransform->Reset();
  120.     FW_CPoint offset(box.left, box.top);
  121.     facetTransform->MoveBy(offset);
  122. }
  123.  
  124. //------------------------------------------------------------------------------
  125. //    • CDrawProxyRun::UsedShapeChanged
  126. //------------------------------------------------------------------------------
  127.  
  128. void CDrawProxyRun::UsedShapeChanged(XMPFrame* xmpFrame)
  129. {
  130.     if (fShape)        // fShape might be null if UsedShapeChanged called early
  131.     {
  132.         // We assume here that all embedded facets have the same
  133.         // externalTransform
  134.         
  135.         XMPFrameFacetIterator* ite = xmpFrame->CreateFacetIterator();
  136.         XMPFacet *xmpFacet = ite->First();
  137.         delete ite;
  138.         
  139.         if (xmpFacet)
  140.         {
  141.             XMPShape *shape = ::NewXMPShape(xmpFrame->GetFrameShape());
  142.             shape->Transform(xmpFacet->GetExternalTransform());
  143.             FW_CRect rect;
  144.             shape->GetBoundingBox(&rect);
  145.             delete shape;
  146.             fShape->ProxyShapeChanged(rect);
  147.         }
  148.     }
  149.     
  150.     FW_CProxyRun::UsedShapeChanged(xmpFrame);
  151. }
  152.  
  153. //------------------------------------------------------------------------------
  154. //    • CDrawProxyRun::MoveBefore
  155. //------------------------------------------------------------------------------
  156.  
  157. void CDrawProxyRun::MoveBefore(CDrawProxyRun* before)
  158. {
  159.     FW_CPartFacetIterator ite(fDrawPart, fDrawPart->GetMainPresentation());
  160.     FW_CFacet* facet;
  161.     while (!ite.IsDone())
  162.     {
  163.         facet = ite.CurrentItem();
  164.         XMPFacetIterator* ite2 = facet->GetXMPFacet()->CreateFacetIterator(kXMPChildrenOnly, kXMPFrontToBack);
  165.         for (XMPFacet* xmpFacet = ite2->First(); ite2->IsNotComplete(); xmpFacet = ite2->Next())
  166.         {
  167.             if (xmpFacet->GetFrame()->GetPart() ==     GetXMPPart())
  168.             {
  169.                 XMPFacetIterator* ite3 = facet->GetXMPFacet()->CreateFacetIterator(kXMPChildrenOnly, kXMPFrontToBack);
  170.                 for (XMPFacet* xmpFacet2 = ite3->First(); ite3->IsNotComplete(); xmpFacet2 = ite3->Next())
  171.                 {
  172.                     if (xmpFacet2->GetFrame()->GetPart() == before->GetXMPPart())
  173.                     {
  174.                         facet->GetXMPFacet()->MoveBefore(xmpFacet, xmpFacet2);
  175.                         break;
  176.                     }
  177.                 }
  178.                 delete ite3;
  179.             }
  180.         }
  181.         delete ite2;
  182.         ite.Next();
  183.     }
  184. }
  185.  
  186. //------------------------------------------------------------------------------
  187. //    • CDrawProxyRun::MoveBehind
  188. //------------------------------------------------------------------------------
  189.  
  190. void CDrawProxyRun::MoveBehind(CDrawProxyRun* behind)
  191. {    
  192.     FW_CPartFacetIterator ite(fDrawPart, fDrawPart->GetMainPresentation());
  193.     FW_CFacet* facet;
  194.     while (!ite.IsDone())
  195.     {
  196.         facet = ite.CurrentItem();
  197.         XMPFacetIterator* ite2 = facet->GetXMPFacet()->CreateFacetIterator(kXMPChildrenOnly, kXMPFrontToBack);
  198.         for (XMPFacet* xmpFacet = ite2->First(); ite2->IsNotComplete(); xmpFacet = ite2->Next())
  199.         {
  200.             if (xmpFacet->GetFrame()->GetPart() ==     GetXMPPart())
  201.             {
  202.                 XMPFacetIterator* ite3 = facet->GetXMPFacet()->CreateFacetIterator(kXMPChildrenOnly, kXMPFrontToBack);
  203.                 for (XMPFacet* xmpFacet2 = ite3->First(); ite3->IsNotComplete(); xmpFacet2 = ite3->Next())
  204.                 {
  205.                     if (xmpFacet2->GetFrame()->GetPart() == behind->GetXMPPart())
  206.                     {
  207.                         facet->GetXMPFacet()->MoveBehind(xmpFacet, xmpFacet2);
  208.                         break;
  209.                     }
  210.                 }
  211.                 delete ite3;
  212.             }
  213.         }
  214.         delete ite2;
  215.         ite.Next();
  216.     }
  217. }
  218.  
  219. //------------------------------------------------------------------------------
  220. //    • CDrawProxyRun::MoveFirst
  221. //------------------------------------------------------------------------------
  222.  
  223. void CDrawProxyRun::MoveFirst()
  224. {
  225.     FW_CPartFacetIterator ite(fDrawPart, fDrawPart->GetMainPresentation());
  226.     FW_CFacet* facet;
  227.     while (!ite.IsDone())
  228.     {
  229.         facet = ite.CurrentItem();
  230.         XMPFacetIterator* ite2 = facet->GetXMPFacet()->CreateFacetIterator(kXMPChildrenOnly, kXMPBackToFront);
  231.         for (XMPFacet* xmpFacet = ite2->First(); ite2->IsNotComplete(); xmpFacet = ite2->Next())
  232.         {
  233.             if (xmpFacet->GetFrame()->GetPart() ==     GetXMPPart())
  234.                 facet->GetXMPFacet()->MoveBefore(xmpFacet, NULL);
  235.         }
  236.         delete ite2;
  237.         ite.Next();
  238.     }
  239. }
  240.  
  241. //------------------------------------------------------------------------------
  242. //    • CDrawProxyRun::MoveLast
  243. //------------------------------------------------------------------------------
  244.  
  245. void CDrawProxyRun::MoveLast()
  246. {
  247.     FW_CPartFacetIterator ite(fDrawPart, fDrawPart->GetMainPresentation());
  248.     FW_CFacet* facet;
  249.     while (!ite.IsDone())
  250.     {
  251.         facet = ite.CurrentItem();
  252.         XMPFacetIterator* ite2 = facet->GetXMPFacet()->CreateFacetIterator(kXMPChildrenOnly, kXMPFrontToBack);
  253.         for (XMPFacet* xmpFacet = ite2->First(); ite2->IsNotComplete(); xmpFacet = ite2->Next())
  254.         {
  255.             if (xmpFacet->GetFrame()->GetPart() ==     GetXMPPart())
  256.                 facet->GetXMPFacet()->MoveBehind(xmpFacet, NULL);
  257.         }
  258.         delete ite2;
  259.         ite.Next();
  260.     }
  261. }
  262.  
  263. //------------------------------------------------------------------------------
  264. //    • CDrawProxyRun::NewProxyBorder
  265. //------------------------------------------------------------------------------
  266.  
  267. FW_CBaseProxyBorder* CDrawProxyRun::NewProxyBorder()
  268. {
  269.     CDrawProxyBorder* border = new CDrawProxyBorder;
  270.     border->InitDrawProxyBorder(this);
  271.     return border;
  272. }
  273.  
  274. //------------------------------------------------------------------------------
  275. //    • CDrawProxyRun::SetSelectState
  276. //------------------------------------------------------------------------------
  277.  
  278. void CDrawProxyRun::SetSelectState(FW_Boolean state)
  279. {
  280.     FW_CProxyRun::SetSelectState(state);
  281.     
  282.     // ----- Set the selected flag in facet -----
  283.     BC_TCollectionActiveIterator<FW_CProxyFrame*> ite(*this->GetProxyFrameList());
  284.     while (!ite.IsDone())
  285.     {
  286.         XMPFrameFacetIterator ite2((*ite.CurrentItem())->GetXMPFrame());
  287.         for (XMPFacet* xmpFacet = ite2.First(); ite2.IsNotComplete(); xmpFacet = ite2.Next())
  288.             xmpFacet->SetSelected(state);
  289.         ite.Next();
  290.     }
  291. }
  292.  
  293. //------------------------------------------------------------------------------
  294. //    • CDrawProxyRun::OffsetProxyFrames
  295. //------------------------------------------------------------------------------
  296.  
  297. void CDrawProxyRun::OffsetProxyFrames(const FW_CPoint& offset)
  298. {
  299.     BC_TCollectionActiveIterator<FW_CProxyFrame*> ite(*this->GetProxyFrameList());
  300.     while (!ite.IsDone())
  301.     {
  302.         (*ite.CurrentItem())->OffsetFrame(offset);
  303.         ite.Next();
  304.     }
  305.  
  306.     GetProxyBorder()->BorderHasChanged(TRUE);
  307. }
  308.  
  309. //------------------------------------------------------------------------------
  310. //    • CDrawProxyRun::PlaceProxyFrames
  311. //------------------------------------------------------------------------------
  312.  
  313. void CDrawProxyRun::PlaceProxyFrames(const FW_CPoint& position)
  314. {
  315.     BC_TCollectionActiveIterator<FW_CProxyFrame*> ite(*this->GetProxyFrameList());
  316.     while (!ite.IsDone())
  317.     {
  318.         (*ite.CurrentItem())->PlaceFrame(position);
  319.         ite.Next();
  320.     }
  321.  
  322.     GetProxyBorder()->BorderHasChanged(TRUE);
  323. }
  324.  
  325. //------------------------------------------------------------------------------
  326. //    • CDrawProxyRun::ResizeProxyFrames
  327. //------------------------------------------------------------------------------
  328.  
  329. void CDrawProxyRun::ResizeProxyFrames(XMPShape* newShape)
  330. {
  331.     BC_TCollectionActiveIterator<FW_CProxyFrame*> ite(*this->GetProxyFrameList());
  332.     while (!ite.IsDone())
  333.     {
  334.         XMPShape *shape = ::NewXMPShape(newShape);
  335.         (*ite.CurrentItem())->ResizeFrame(shape);
  336.         ite.Next();
  337.     }
  338.     delete newShape;
  339.     GetProxyBorder()->BorderHasChanged(TRUE);
  340. }
  341.  
  342.